package com.naiterui.ehp.bp.utils.encypt;

import java.util.Base64;

import cn.hutool.crypto.Mode;
import cn.hutool.crypto.Padding;
import cn.hutool.crypto.symmetric.DES;

/**
 * @author luao
 * @date 2021/8/11 2:22 下午
 **/
public class DESUtil {

    /**
     * des加密
     *
     * @param secret
     * @param content
     * @return
     */
    public static String desEncrypt(String secret, String content) {
        DES des = new DES(Mode.CBC, Padding.PKCS5Padding, secret.getBytes(), secret.getBytes());
        byte[] encrypted = des.encrypt(content);
        return Base64.getEncoder().encodeToString(encrypted);
    }

    /**
     * des解密
     *
     * @param secret
     * @param content
     * @return
     */
    public static String desDecrypt(String secret, String content) {
        DES des = new DES(Mode.CBC, Padding.PKCS5Padding, secret.getBytes(), secret.getBytes());
        return des.decryptStr(content);
    }
}
